
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for friends_add_comments.
	''' </summary>
	Public Partial Class friends_add_comments
		Inherits BaseWebPage

		Private usrID As Integer = -1
		Private grpID As Integer = -1
		Private isGroupMode As Boolean = False
		Private grp As Group = Nothing
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.FRIEND_ADD_COMMENTS_PAGE;
			Dim usr As User = LoggedUser

			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			Me.initPageTitles(Constants.FRIENDS_ADD_COMMENT, "", frmAddComment, Nothing, htPageConstants)
			Me.initAdvertisements(frmAddComment, Nothing)

			' init group
			If Request.Params(Constants.GROUP_PARAM) <> Nothing AndAlso Request.Params(Constants.GROUP_PARAM) <> "" Then
				isGroupMode = True
				grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
				grp = Groups.GetGroupByID(grpID)
				If grp = Nothing Then
					Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
				End If
				If Not grp.Members.Contains(usr.ID) Then
					Throw New Exception(Constants.ERROR_MESSAGE_ONLY_MEMBERS_ACCESS)
				End If
			End If

			If Request.Params("usr") = Nothing Then
				usr = LoggedUser
			Else
				usrID = Convert.ToInt32(Request.Params("usr"))
				usr = Users.GetUserByID(usrID)
			End If

			If isGroupMode Then
				lblAbout.Text = (Me.GetPageConstText(htPageConstants, "CONST_PageTitle_TEXT")).Replace("[PARAM]", grp.Name)

				hlBackToGroup.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + grpID
				hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)

				'btnPost.Attributes["onclick"] = "javascript:return confirm('" + Constants.GONFIRM_MESSAGE_ADD_GROUP_COMMENTS + "');";

				trUserShortCut.Visible = False
			Else
				lblAbout.Text = (Me.GetPageConstText(htPageConstants, "CONST_PageTitle_TEXT")).Replace("[PARAM]", usr.Name)

				If Not usr.DirectFriends.Contains(LoggedUser.ID) Then
					Response.Redirect(Constants.COMMENTS_CONFIRMATION + "?usr=" + usrID + "&conf=no")
				End If

				'btnPost.Attributes["onclick"] = "javascript:return confirm('" + Constants.GONFIRM_MESSAGE_ADD_USER_COMMENTS + "');";

				If usr <> Nothing AndAlso usr.ID <> LoggedUser.ID Then
					ucMemberShortcut.UserID = usr.ID
				Else
					trUserShortCut.Visible = False
				End If
			End If

			txtComments.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_USER_COMMENTS_MAX_CHARS.ToString()))
			txtComments.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_USER_COMMENTS_MAX_CHARS.ToString()))
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If Page.IsValid Then
				Dim usr As User = Users.GetUserByID(usrID)
				Dim loggedUsr As User = LoggedUser

				Dim comment As String = ""
				comment = removeScriptTags(txtComments.Text.Trim())
				comment = removeScriptTags(comment.Substring(0, Math.Min(comment.Length, Constants.TEXT_AREA_USER_COMMENTS_MAX_CHARS)))

				lblComment.Text = comment
				trCommentPost.Visible = False
				trConfrimation.Visible = True
				lblAbout.Text = Me.GetPageConstText(htPageConstants, "CONST_PageTitleConfirm_TEXT")
			End If
		End Sub

		Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If isGroupMode Then
				Response.Redirect(Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID)
			Else
				Response.Redirect(Constants.MEMBERS + "?id=" + usrID)
			End If
		End Sub

		Protected Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim usr As User = Users.GetUserByID(usrID)
			Dim loggedUsr As User = LoggedUser

			Dim comment As String = lblComment.Text

			If isGroupMode Then
				grp.AddComment(loggedUsr.ID, comment)
				Response.Redirect(Constants.COMMENTS_CONFIRMATION + "?usr=" + usrID + "&" + Constants.GROUP_PARAM + "=" + grp.ID + "&conf=yes")
			Else
				usr.AddComment(loggedUsr.ID, comment)
				Response.Redirect(Constants.COMMENTS_CONFIRMATION + "?usr=" + usrID + "&conf=yes")
			End If
		End Sub

		Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			trCommentPost.Visible = True
			trConfrimation.Visible = False
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable frmAddComment.
		====================
		Public ReadOnly Property frmAddComment() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_frmAddComment
			End Get
		End Property
		'set { Migrated_frmAddComment = value; }
	End Class
End Namespace






